package com.knightboy.smartshoes.core;

import android.os.Handler;

/**
 * Created by knightBoy on 2015/7/19.
 * 未解决问题：初始化时获取足压建议，体重
 */
public class DataHelper {
    private static Handler mHandler = new Handler();
    /**
     * 应用启动时，判断是否是刚启动，获得远程数据
     */
    public static void init(){
        if(SharedData.getIsStart()){
            //获得足压建议，体重
            String suggestion = "";
            double lastWeight = 50.3;

            //存入数据类
            SharedData.setSuggestion(suggestion);
            SharedData.setLastWeight(lastWeight);

            //修改初始化标志
            SharedData.setIsStart();
        }
    }

    /**
     * 实现计步功能，并实现各个数据的更新
     * @param speed
     * @param aDistance
     */
    public static void countStep(double speed, double aDistance){
        //如果是第一步
        if(SharedData.getIsFirstStep()){
            SharedData.firstUpdateData(speed, aDistance);
            SharedData.setIsFirstStep();
        }else{
            SharedData.updateData(speed, aDistance);
        }
        //延迟500ms后步数加1
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
               SharedData.step++;
            }
        }, 600);
    }

    public static void setTwoStress(double stressOne, double stressTwo){
        if(SharedData.getIsFirstStep()){
            //设置足压，体重，比率
            SharedData.setStress(stressOne, stressTwo);
            SharedData.setWeight(53.5);       //体重需要进行其它方面的计算
//            SharedData.setWeight(stressTwo * 0.1191);       //体重需要进行其它方面的计算
            SharedData.setRate((int) (SharedData.weight / SharedData.lastWeight));
        }else{
            SharedData.setStress(stressOne,stressTwo);
        }
    }
}
